package demo1;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class Test1 {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java109?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("0118");
        Connection connection = dataSource.getConnection();
        Student s0 = new Student(1, "张三");
        Student s1 = new Student(2, "王五");
        Student s2 = new Student(3, "李四");
        Student s3 = new Student(4, "赵六");

        InsertStudent.insert(connection,s1);
        InsertStudent.insert(connection,s2);
        InsertStudent.insert(connection,s0);
        InsertStudent.insert(connection,s3);
        SelectStudent.select(connection, -1);

        UpdateStudent.update(connection,1 , "曹操");
        SelectStudent.select(connection,-1);

        DeleteStudent.delete(connection, 2);
        SelectStudent.select(connection,-1);

    }
}
